
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                            start.c
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                                                    Forrest Yu, 2005
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

#include "type.h"/*主要定义了U32 U16 U8*/
#include "const.h" /*主要定义了#define	GDT_SIZE	128*/
#include "protect.h"/* 主要定义了typedef struct s_descriptor*/

/*对于汇编文件不用include声明，这是c语言的用法。*/
/*在string.asm中定义*/
PUBLIC	void*	memcpy(void* pDst, void* pSrc, int iSize);
/* 在klib.asm中定义*/
PUBLIC	void	disp_str(char * pszInfo);

/*一个GDTR寄存器6字节。48位。0-15代表长度，16-47表示旧GDT地址*/
PUBLIC	u8		gdt_ptr[6];	/* 0~15:Limit  16~47:Base */

/*这个在堆栈中的GDT表*/
PUBLIC	DESCRIPTOR	gdt[GDT_SIZE]; /*128个描述符*/

PUBLIC void cstart()
{
/*由于disp_pos初始化为0，如果直接显示会覆盖已经显示的区域。所以使用多种回车，跳过。*/
	disp_str("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
		 "-----\"cstart\" begins-----\n");
     disp_str("DSPOS GDT is  created！\n");


	/* 将 LOADER 中的 GDT 复制到新的 GDT 中 */
	memcpy(&gdt,				   /* New GDT */
	       (void*)(*((u32*)(&gdt_ptr[2]))),    /* Base  of Old GDT */
	       *((u16*)(&gdt_ptr[0])) + 1	   /* Limit of Old GDT */
		);/*三个参数，DST SRC SIZE*/
	
/* gdt_ptr[6] 共 6 个字节：0~15:Limit  16~47:Base。用作 sgdt/lgdt 的参数。*/
	u16* p_gdt_limit = (u16*)(&gdt_ptr[0]);
	u32* p_gdt_base  = (u32*)(&gdt_ptr[2]);
	*p_gdt_limit = GDT_SIZE * sizeof(DESCRIPTOR) - 1; 
	*p_gdt_base  = (u32)&gdt;  
/*关键：根据堆栈中gdt[GDT_SIZE];来重新设置gdt_ptr[6]的值*/
}
